<?php
/**
 * @version 	$Id: fException.class.php 74 2010-03-17 06:48:21Z mylifeisskidrow@gmail.com $
 * @author 		$Author: mylifeisskidrow@gmail.com $
 * @copyright 	Copyright (c) 2010 Luu Trong Hieu. All right reserved.
 * @license 	GNU/GPL see license.php
 */

defined('IN_FLYWHEEL') or die('Restricted Access');

/**
 * Exception
 * 
 * @package 	system
 * @subpackage 	exception
 *
 */
class fException extends Exception {
	/**
	 * Cause for wrap exception
	 *
	 * @var instance of fException
	 */
	protected $cause;
	
	function __construct($p1, $p2 = null) {

		$cause = null;

		if ($p2 !== null) {
			$msg = $p1;
			$cause = $p2;
		} else {
			if ($p1 instanceof Exception) {
				$msg = '';
				$cause = $p1;
			} else {
				$msg = $p1;
			}
		}

		parent::__construct($msg);

		if ($cause !== null) {
			$this->cause = $cause;
			$this->message .= ' [wrapped: ' . $cause->getMessage() .']';
		}
	}

	/**
	 * Get Cause Exception
	 *
	 * @return exception
	 */
	public function getCause() {
		return $this->cause;
	}
	
	/**
	 * Print Stack Trace
	 * 	prints the stack trace for this exception.
	 * 
	 * @return void
	 */
	public function printStackTrace() {
		print_r($this->getTrace());
	}
}